<?php
/**
 * Created by 云中有鹿.
 * User: 陈云
 * Blog: http://blog.likecy.cn
 * Date: 2019-04-05
 * Time: 19:26
 */

namespace app\car\model;


use app\common\model\User;
use think\Model;

class Task extends Model
{
    protected $name = "car_task";
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'start_time';
    protected $updateTime = 'end_time';
    public function getStartTimeAttr($value, $data)
    {
        return date('Y-m-d H:i',$data['start_time']);
    }
    public function getEndTimeAttr($value, $data)
    {
        return date('Y-m-d H:i',$data['end_time']);
    }

    public function getStopTimeAttr($value, $data)
    {
        return date('Y-m-d H:i',$data['stop_time']);
    }
    public function  line(){
        return $this->belongsTo('Line','line_id','id');
    }
    public function  carinfo(){
        return $this->belongsTo('CarInfo','carinfo_id','id');
    }
    public function  driver(){
        return $this->belongsTo('Driver','dri_id','id');
    }
//    public function  driver(){
//        return $this->belongsToMany('User','car_driver','dir_id','id');
//    }



    public static function getTask(){
       return self::with(['carinfo','line','driver'])->where('status','1')->select();
    }
}